package com.magist.core.util;

import com.magist.core.enums.BaseEnum;
import org.springframework.util.StringUtils;

/**
 * 将枚举的对应的字段排序
 */
public class EnumOrderUtil {


    public static String orderEnum(Enum[] enums, String orderTxt) {
        if(StringUtils.isEmpty(orderTxt) || !orderTxt.contains(",")) {
            return orderTxt;
        }
        String orderAfter = "";
        String[] split = orderTxt.split(",");
        for (Enum anEnum : enums) {
            BaseEnum be = (BaseEnum) anEnum;
            String code = be.getCode();
            for (String s : split) {
                if (code.equals(s)) {
                    orderAfter += be.getCode() + ",";
                    break;
                }
            }
        }
        if(orderAfter.endsWith(",")) {
            orderAfter = orderAfter.substring(0, orderAfter.length() - 1);
        }

        return orderAfter;

    }
}
